﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using System.Drawing;

namespace Jemgine.MapEditor
{
    [Tools.SelectableTool]
    public class SelectTool : Tool
    {
        public bool AddToMultiselection { get; set; }

        public SelectTool()
        {
            AddToMultiselection = false;
        }

        public override Image GetIcon() { return System.Drawing.Image.FromFile("ToolIcons/select.bmp"); }

        private Engine.Selection FindNextSelection(Vector2 MousePosition, Engine.Selection StartAt, EditorState EditorState)
        {
            List<Engine.Selection> Stack = EditorState.GetElementStack(MousePosition);
            if (Stack.Count == 0) return Engine.Selection.None;

            int Result = Stack.IndexOf(StartAt);
            ++Result;
            if (Result >= Stack.Count) Result = 0;
            return Stack[Result];
        }

        public override void MouseDown(MouseInputState InputState, EditorState EditorState)
        {
            EditorState.SelectItemEx(FindNextSelection(InputState.Position, EditorState.Selected, EditorState));
        }
    }
}
